package com.example.pet.controller;



import com.example.pet.entity.*;
import com.example.pet.service.*;
import com.example.pet.service.impl.CommentServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;


@RestController
@Api(tags = "互动/我的页面")
@RequestMapping("post")
public class PostController  {
  @Resource
  private PostService postService;
  @Resource
  private PphotoService pphotoService;
  @Resource
  CollectService collectService;
  @Resource
  CommentService commentService;
  @Resource
  PhotoService photoService;
  @Resource
  FriendsService friendsService;
  @ApiOperation("互动数据")
  @GetMapping("/dot")
  public List<Post> dot(){
    List<Post> all = postService.getAll();
    for (Post post : all) {
      List<Pphoto> all1 = pphotoService.getAll();
      for (Pphoto pphoto : all1) {
        if(post.getPostId() == pphoto.getPostId()){
          post.setImage(pphoto.getPostImage());
        }
        Photo all4 = photoService.getAll(post.getUserId());
        post.setUserImage(all4.getImage());
        post.setUserName(all4.getUserName());
      }
      List<Collect> all2 = collectService.getAll(post.getPostId());
      post.setCollect(all2.size());
      List<Comment> all3 = commentService.getAll(post.getPostId());
      post.setComment(all3.size());

    }
    return all;
  }
  @ApiImplicitParams({
//        required=》参数是否必须传  paramType=》参数放在哪个位置 dataType=》参数类型(默认：String)
//        path=》请求参数的获取
          @ApiImplicitParam(name = "userId",value = "用户的id,登录成功后给了的",required = true,paramType = "query"),
  })
  @ApiOperation("个人中心数据")
  @GetMapping("wode")
  public woDe wode(Integer userId){
    woDe woDe = new woDe();
    Photo all = photoService.getAll(userId);
    woDe.setUserName(all.getUserName());
    woDe.setUserImage(all.getImage());
    List<Comment> all1 = commentService.get(userId);
    woDe.setComment(all1.size());
    List<Collect> all2 = collectService.get(userId);
    woDe.setCollect(all2.size());
    List<Friends> all3 = friendsService.getAll(userId);
    woDe.setFriends(all3.size());
    return woDe;
  }
  }

